<template>
	<view class="">
		<view class="swipers">
			<view class="uni-padding-wrap">
				<view class="page-section swiper">
					<view class="page-section-spacing">
						<swiper class="swiper" :indicator-dots="indicatorDots" indicator-color="rgba(255,255,255,.6)"
						 indicator-active-color="#fff" active-class='swioe' :autoplay="autoplay" :interval="interval" :duration="duration"
						 previous-margin='10px' next-margin='10px' circular='true'>
							<swiper-item v-for="val in indexs.banner">
								<view class="swiper-item uni-bg-red">
									<image :src="val.image" mode="aspectFill" @click="tiaoz(val.url)"></image>
								</view>
							</swiper-item>


						</swiper>
					</view>
				</view>
			</view>
		</view>
		<!-- index导航 -->
		<view class="daohang acea-row row-between-wrapper">
			<view class="item" @tap="qie3(val.url)" v-for="val in indexs.cate">
				<image :src="val.more.thumbnail" ></image>
				<view class="text-center">{{val.name}}</view>
			</view>
		</view>
		<!-- zhengzai -->

		<view class="daohang2">
			<view class="titleset acea-row row-between-wrapper">
				<view class="andLeft">
					正在直播<text>热门课程</text>
				</view>
				<view class="acea-row" @tap="qie('/pages/index-yxjt/index-yxjt?type=1')">
					<view class="nam">更多</view>
					<image src="../../static/y.png" mode=""></image>
				</view>
			</view>
			<view>
				<scroll-view class="scroll-view_H" scroll-x="true">
					<view class="scroll-view_H_tops" v-for="val in indexs.zhibo" @click="urlSet(val.post_url,val.status,val.id)">
						<view class="scroll-view-item_H" hover-class="none">
							<image :src="val.more.thumb" mode="aspectFill"></image>
							<view class="zhangtai  acea-row row-center-wrapper" :class="val.status==0?'backcolor1':'backcolor2'">
								<span></span>
								<view>{{val.icon}}</view>
							</view>
							<view class="name">
								<view class="title textline">{{val.post_title}}</view>
								<view class="acea-row  row-between-wrapper">
									<view>
										<view class="acea-row topsi">
											<view class="zhuyao">主讲：{{val.post_ren}}</view>
											<view class="zhuanye textline">{{val.post_yy}}</view>
										</view>
										<view class="acea-row timesc">
											<image src="../../static/z.png"></image>
											<view>直播时间：{{val.post_times}}</view>
										</view>
									</view>
									<view :class="val.status == 1?'biaoqian' :'yuyues'">
										{{val.button}}
									</view>

								</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		<!-- fernlei -->
		<view class="fenlei">
			<view class="toubus">
				<scroll-view class="scroll-view_H2" scroll-x="true">
					<view class="scroll-view_H_tops2 " :class="active==ind ? 'active' :''" @tap="qiehuan(ind)" v-for="(val,ind) in indexs.list">{{val.name}}<span></span></view>
				</scroll-view>
			</view>
			<view class="lists acea-row row-between-wrapper" v-for="val in fenlei" @click="urlSet(val.post_url,val.status,val.id)">
				<!-- <view class="zhangtai  acea-row row-center-wrapper" :class="val.status == 0?'backcolor1':'backcolor2'">
					<span></span>
					<view>{{val.icon}}</view>
				</view> -->
				<image :src="val.thumbnail"></image>
				<view class="rits">
					<view class="title textline">{{val.post_title}}</view>
					<view class="acea-row Jud">
						<view class="jiangjie">主讲：{{val.post_ren}}</view>
						<view class="zhuanyei textline">{{val.post_yy}}</view>
					</view>
					<view class="acea-row row-between-wrapper botts">
						<view class="acea-row ">
							<image src="../../static/z.png"></image>
							<view class="time">{{val.post_times}}</view>
						</view>
						<view class="biaoqian">
							{{val.button}}
						</view>
					</view>
				</view>
			</view>

			<view class="acea-row row-center-wrapper genduos" @tap="qie('/pages/index-yxjt/index-yxjt?type=2')">
				<view>查看更多</view>
				<image src="../../static/y.png"></image>
			</view>
		</view>
		<!-- 今日推荐 -->
		<view class="index_tuijian">
			<view class="titleset acea-row row-between-wrapper">
				<view class="andLeft">
					今日推荐<text>健康知识</text>
				</view>
				<view class="acea-row" @tap="qie('/pages/index-ghs/index-ghs?cid=3')">
					<view class="nam">更多</view>
					<image src="../../static/y.png" mode=""></image>
				</view>
			</view>
			<view class="order_img" v-for='val in indexs.push' @click="keysz(val.id,val.category_id)">
				<image :src="val.thumbnail" mode="aspectFill"></image>
				<view class="szhji">
					<view class="biao">{{val.post_keywords}}</view>
					<view class="ti">{{val.post_title}}</view>
				</view>
			</view>

		</view>



		<view class="acea-row row-center-wrapper" style="height: 100rpx;font-size: 20rpx;"><text>已经到底了 ~</text></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				indexs: [],
				active:0,
				fenlei:[]
			}
		},
		onLoad(e) {
			console.log(e)
			uni.setStorageSync('code', e.code)
			this.code = e.code
			console.log(e.code)

			var jweixin = require('jweixin-module')
			var that = this
			console.log(jweixin)
			var urls = window.location.href
			console.log(urls)
			this.$api('/portal/index/jsconfig',  {datas:{url:urls}}, function(res) {
				console.log(res)
				var s = res.data.data
				jweixin.config({
		 		    debug: false,
				    appId: s.appId,
				    timestamp: s.timestamp,
				    nonceStr: s.nonceStr,
				    signature:s.signature,
				    jsApiList: ["updateTimelineShareData","updateAppMessageShareData"]
				});
				jweixin.ready(function(){
					jweixin.updateTimelineShareData({
							title: '海绵医学院', // 分享标题
						    link: urls, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
						    imgUrl: 'http://api.haimiantv.cn/upload/default/20200426/86ea4921376b6656f24fbb40e674b361.png', // 分享图标
						    success: function () {
						      // 设置成功
							  console.log(1)

						    }
					})
					jweixin.updateAppMessageShareData({
						title: '海绵医学院', // 分享标题
						desc: '一个专业/有态度的医学直播交流平台', // 分享描述
						link: urls, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
						imgUrl: 'http://api.haimiantv.cn/upload/default/20200426/86ea4921376b6656f24fbb40e674b361.png', // 分享图标
						success: function () {
						  // 设置成功
						}
					  })



				})
				jweixin.error(function(res){
					console.log(res)
				})
			})
		},

		onShow() {
				this.index()
		},
		methods: {
			keysz(id,cid){
				uni.navigateTo({
					url:'../kepuxq/kepuxq?id='+id+'&cid='+cid
				})
			},
			tiaoz(e){
				// window.location.href = e
				if(e == '' || e == undefined){
					return false
				}
				window.location.href = e
				// uni.navigateTo({
				// 	url:'../webView/webView?url='+e
				// })
			},
			qie3(e){
				window.location.href = e

			},
			urlSet(e,type,id){
				console.log(type)
				var url = e
				var that = this

				if(type == 0){
					// 可预约
					console.log(id)
					var ids = uni.getStorageSync('ids')
					console.log(id)
					this.$api('/portal/index/yy',{datas:{id:id,user_id:ids}},function(res){
						console.log(res)
						var icon
						if(res.data.code == 200){
							icon = 'success'
						}else{
							icon = 'none'
						}
						uni.showToast({
							title:res.data.msg,
							icon:icon,
							duration:1500
						})
					})
				}else{
					console.log(url)

					if(url == '' || url == undefined){
						return false
					}
					window.location.href = e
					// uni.navigateTo({
					// 	url:'../webView/webView?url='+url
					// })
				}
			},
			qie(e) {
				uni.navigateTo({
					url: e,

				})
			},
			qiehuan(e){
				this.active = e
				var list = this.indexs.list[e].child
				this.fenlei = list
			},
			index() {
				var that = this
				// uni.request({
				// 	url:'/portal/index/index',
				// 	 success: (res) => {
				// 	        console.log(res.data);
				// 	    }
				// })
				var user_id = uni.getStorageSync('ids')
				if(user_id ==undefined  || user_id == null || user_id ==''){
					this.$api('/portal/index/oauth_callback', {
						datas: {
							code: that.code
						}
					}, function(res) {
						console.log(res)
							uni.setStorageSync('ids', res.data.data.id)
					})
				}

				that.$api('/portal/index/index', {}, function(res) {
					console.log(res)
					that.indexs = res.data.data
					that.fenlei = res.data.data.list[0].child
				})
			},
			qie2(e) {
				uni.switchTab({
					url: e
				})
			}
		}
	}
</script>

<style>
	@import url("./css/index.css");
</style>
